using HKB.Common;
using HKB.Data.Model;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace HKB.Data.Dal
{
	public class UserGiftCardFestivalDal
	{
		public bool Exists(string FestivalName)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select count(1) from MBF_UserGiftCardFestival");
			stringBuilder.Append(" where ");
			stringBuilder.Append("FestivalName = @FestivalName ");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@FestivalName", SqlDbType.NVarChar, 50)
			};
			array[0].Value = FestivalName;
			return Conn.Exists(stringBuilder.ToString(), array);
		}
		public void Add(UserGiftCardFestivalModel model)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("insert into MBF_UserGiftCardFestival(");
			stringBuilder.Append("FestivalName,FestivalBegin,FestivalEnd,FestivalType");
			stringBuilder.Append(") values (");
			stringBuilder.Append("@FestivalName,@FestivalBegin,@FestivalEnd,@FestivalType");
			stringBuilder.Append(") ");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@FestivalName", SqlDbType.NVarChar, 50),
				new SqlParameter("@FestivalBegin", SqlDbType.Date, 3),
				new SqlParameter("@FestivalEnd", SqlDbType.Date, 3),
				new SqlParameter("@FestivalType", SqlDbType.Int, 4)
			};
			array[0].Value = model.FestivalName;
			array[1].Value = model.FestivalBegin;
			array[2].Value = model.FestivalEnd;
			array[3].Value = model.FestivalType;
			Conn.ExecuteSql(stringBuilder.ToString(), array);
		}
		public bool Update(UserGiftCardFestivalModel model)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("update MBF_UserGiftCardFestival set ");
			stringBuilder.Append(" FestivalName = @FestivalName , ");
			stringBuilder.Append(" FestivalBegin = @FestivalBegin , ");
			stringBuilder.Append(" FestivalEnd = @FestivalEnd , ");
			stringBuilder.Append(" FestivalType = @FestivalType  ");
			stringBuilder.Append(" where FestivalName=@FestivalName  ");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@FestivalName", SqlDbType.NVarChar, 50),
				new SqlParameter("@FestivalBegin", SqlDbType.Date, 3),
				new SqlParameter("@FestivalEnd", SqlDbType.Date, 3),
				new SqlParameter("@FestivalType", SqlDbType.Int, 4)
			};
			array[0].Value = model.FestivalName;
			array[1].Value = model.FestivalBegin;
			array[2].Value = model.FestivalEnd;
			array[3].Value = model.FestivalType;
			int num = Conn.ExecuteSql(stringBuilder.ToString(), array);
			return num > 0;
		}
		public bool Delete(string FestivalName)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("delete from MBF_UserGiftCardFestival ");
			stringBuilder.Append(" where FestivalName=@FestivalName ");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@FestivalName", SqlDbType.NVarChar, 50)
			};
			array[0].Value = FestivalName;
			int num = Conn.ExecuteSql(stringBuilder.ToString(), array);
			return num > 0;
		}
		public UserGiftCardFestivalModel GetModel(string FestivalName)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select FestivalName, FestivalBegin, FestivalEnd, FestivalType  ");
			stringBuilder.Append("  from MBF_UserGiftCardFestival ");
			stringBuilder.Append(" where FestivalName=@FestivalName ");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@FestivalName", SqlDbType.NVarChar, 50)
			};
			array[0].Value = FestivalName;
			UserGiftCardFestivalModel userGiftCardFestivalModel = new UserGiftCardFestivalModel();
			DataSet dataSet = Conn.Query(stringBuilder.ToString(), array);
			UserGiftCardFestivalModel result;
			if (dataSet.Tables[0].Rows.Count > 0)
			{
				userGiftCardFestivalModel.FestivalName = dataSet.Tables[0].Rows[0]["FestivalName"].ToString();
				if (dataSet.Tables[0].Rows[0]["FestivalBegin"] != null && dataSet.Tables[0].Rows[0]["FestivalBegin"].ToString() != "")
				{
					userGiftCardFestivalModel.FestivalBegin = new System.DateTime?(System.DateTime.Parse(dataSet.Tables[0].Rows[0]["FestivalBegin"].ToString()));
				}
				if (dataSet.Tables[0].Rows[0]["FestivalEnd"] != null && dataSet.Tables[0].Rows[0]["FestivalEnd"].ToString() != "")
				{
					userGiftCardFestivalModel.FestivalEnd = new System.DateTime?(System.DateTime.Parse(dataSet.Tables[0].Rows[0]["FestivalEnd"].ToString()));
				}
				if (dataSet.Tables[0].Rows[0]["FestivalType"] != null && dataSet.Tables[0].Rows[0]["FestivalType"].ToString() != "")
				{
					userGiftCardFestivalModel.FestivalType = new int?(int.Parse(dataSet.Tables[0].Rows[0]["FestivalType"].ToString()));
				}
				result = userGiftCardFestivalModel;
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataSet GetList(string strWhere)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select * ");
			stringBuilder.Append(" FROM MBF_UserGiftCardFestival ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
		public DataSet GetList(int Top, string strWhere, string fieldOrder)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select ");
			if (Top > 0)
			{
				stringBuilder.Append(" top " + Top.ToString());
			}
			stringBuilder.Append(" * ");
			stringBuilder.Append(" FROM MBF_UserGiftCardFestival ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			stringBuilder.Append(" order by " + fieldOrder);
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
		public DataSet GetListRowid(int Top, string strWhere, string fieldOrder, params string[] selectField)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select ");
			if (Top > 0)
			{
				stringBuilder.Append(" top " + Top.ToString());
			}
			string text = "*";
			if (selectField.Length > 0)
			{
				text = selectField[0];
				if (text.Trim() == "")
				{
					text = "*";
				}
			}
			stringBuilder.AppendFormat(" ROW_NUMBER() OVER (ORDER BY FestivalName ASC) rowid,{0} ", text);
			stringBuilder.Append(" FROM MBF_UserGiftCardFestival ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			stringBuilder.Append(" order by " + fieldOrder);
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
	}
}
